#include<iostream>
#include<cstdlib>
#include"BiTree.h"
using namespace std;

int Level_X(BTNode* root, ElemType x, int level = 1)
{
	if (!root)
		return 0;
	if (root->data == x)
		return level;

	int llevel = Level_X(root->lchild, x, level + 1);
	int rlevel = Level_X(root->rchild, x, level + 1);

	if (llevel == 0 && rlevel == 0)
		return 0;
	else if (llevel != 0)
		return llevel;
	else
		return rlevel;
}

int main()
{
	/*
		1
	5       2
		 3     4
	*/
	BTNode* BTree;
	ElemType a[] = { 1,5,2,3,4 };
	ElemType b[] = { 5,1,3,2,4 };

	BTree = CreateBTree(a, b, 5);

	int level = Level_X(BTree, 4);

	cout << level << endl;

	return 0;
}